import Vue from 'vue'
import CModalTipsCell from './CModalTipsCell.vue'
const CModalTipsCellBox = Vue.extend(CModalTipsCell)

/**
 * 设置不同类型的提示弹框
 * this.$UniModalTips.error("删除失败！")
 */
var UniModalTips = {
    confirm: (options)=> {
        setOptions(options,"confirm");   // 询问状态
    },
    delete: (options)=> {
        setOptions(options,"delete");  // 警告状态
    },
    success: (options)=> {
        setOptions(options,"success");   // 成功状态
    },
    error: (options)=> {
        setOptions(options,"error");   // 失败状态
    },
	tips: (options)=> {
		setOptions(options,"tips");   // 提示信息
	}
}
/**
 * 参数配置
 */
var setOptions = (options,type)=>{
        let showType = type;
        if (options === undefined || options === null) {
            // 判断传进来的参数，空/未定义，则显示options对象及为空的content
            options = {
                content: ''
            }
        } else if (typeof options === 'string' || typeof options === 'number') {
            // 参数如果是字符串或者数值，则赋值给options对象的content
            options = {
                content: options
            }
        }
        // 提示弹框的类型
        options.type = showType;
        // 根据提示弹框类型设置默认值
        switch(showType) {
            case "confirm":
                
                break;
            case "delete":
                options.content = options.content || "删除后将不能恢复，是否继续删除？";
                break;
            case "success":
                options.cancelText = options.cancelText || "";   // 提示信息不显示"取消"按钮
                break;
            case "error": 
                options.cancelText = options.cancelText || "";   // 提示信息不显示"取消"按钮
                break;
			case "tips": 
				options.cancelText = options.cancelText || "";   // 提示信息不显示"取消"按钮
				break;
            
        }
        let instance = new CModalTipsCellBox({
            data: options
        })
        instance.$mount();
        document.body.appendChild(instance.$el);
        Vue.nextTick(() => {
            instance.visible = true;
        })
    };


export default UniModalTips